using System;
using System.Collections.Specialized;
using Vici.Mvc;

namespace Demo.ViciMvc
{
    public class DataObjectCreator : IObjectBinder
    {
        public bool TryConvert(string value, Type objectType, out object obj)
        {
            if (objectType == typeof(Employee))
            {
                int id = TypeHelper.ConvertString<int>(value);

                obj = DataService.LoadEmployee(id);

                return (obj != null);
            }

            if (objectType == typeof(Department))
            {
                int id = TypeHelper.ConvertString<int>(value);

                obj = DataService.LoadDepartment(id);

                return (obj != null);
            }

            obj = null;

            return false;
        }

        public bool TryConvert(Type objectType, out object obj, NameValueCollection clientData)
        {
            throw new NotImplementedException();
        }
    }
}
